<?php
class produk_model extends CI_Model{
	function __construct()
	{
		parent::__construct();
		
	}
	
	function get_produk()
	{
		$this->db->select('*');
		$this->db->from('produk');
        $query=$this->db->get();
		return $query;
	}
	
	function get_tags($id_produk){
		$this->db->select('*');
		$this->db->from('tags');
		$this->db->where('tags.id_produk',$id_produk);
		$query=$this->db->get();
		return $query;
	}
	
	function get_id_produk($id){
		$this->db->select('*');
		$this->db->from('produk');
		$this->db->where('produk.id_produk',$id);
        $query=$this->db->get();
		return $query;
	}
	
	function insert_tag($id_produk, $keyword)
	{
		$tags=array('id_tags'=>"", 'id_produk'=>$id_produk,'keyword'=>$keyword);
		$this->db->insert('tags',$tags);	
	}
	
	function delete_tag($keyword)
	{
		$this->db->where('keyword', $keyword);
		$this->db->delete('tags');
	}
	
	function edit_tag($keyword_lama, $keyword_baru){
		$this->db->where('keyword',$keyword_lama);
		$this->db->set('keyword',$keyword_baru );
		$query=$this->db->update('tags');
	
	}
	
	function get_stok_produk($id_produk){
		$this->db->select('*');
		$this->db->from('stok_barang');
		$this->db->where('stok_barang.id_produk',$id_produk);
        $query=$this->db->get();
		return $query;
	}
	
	
	function liat_tags(){
		$query = $this->db->query("SELECT distinct keyword FROM `tags`");
		return $query;
	}
	
	function link_tag($tag){
		$this->db->select('id_produk');
		$this->db->from('tags');
		$this->db->where('keyword', $tag);
		$query = $this->db->get();
		return $query;
	}
	
	function ambil_gambar(){
		$sql = "SELECT * FROM `produk`";
		$query = $this->db->query($sql);
		return $query;
	}

	function insert_review($id_produk, $review){
		$data = array('id_review'=>"", 'id_produk'=>$id_produk, 'review'=>$review);
		$this->db->insert('review',$data);

	}
	
	function komen($id_produk){
		$hasil = $this->db->query("SELECT * FROM produk as p left join review as r on p.id_produk = r.id_produk WHERE p.id_produk =".$id_produk);
		//return $hasil;
		/*$this->db->select('*');
		$this->db->from('review');
		//$this->db->join('review','produk.id_produk=review.id_produk', 'left');
		$this->db->where('review.id_produk', $id_produk);
		$hasil = $this->db->get();*/
		return $hasil;

	}
	
	function desk($id_produk){
		$this->db->select('*');
		$this->db->from('produk');
		$this->db->where('id_produk', $id_produk);
		$hasil = $this->db->get();
		return $hasil;
	}

	
	
}
?>